{extend name="admin/public/base" /}

{block name="content"}
<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    组更新
    <small></small>
  </h1>
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
    <li><a href="#">用户</a></li>
    <li class="active">组更新</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="box box-solid">
           <form method="post" id="form" action="" class="form-horizontal">
              <!-- Custom Tabs -->
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">基本信息</a></li>
                </ul>
                <div class="tab-content">
                  <div class="tab-pane active" id="tab_1">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">组名称</label>
                            <div class="col-sm-5">
                                <input type="text" name="name" value="{$data.name}" class="form-control">
                            </div>
                            <div class="col-sm-5"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注说明</label>
                            <div class="col-sm-5">
                                <textarea class="form-control" name="remark">{$data.remark}</textarea>
                            </div>
                            <div class="col-sm-5"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">权限分配</label>
                            <div class="col-sm-10">
                                <div class="table-responsive">
                                    <table cellpadding="1" cellspacing="1" class="table">
                                        <thead>
                                            <tr>
                                                <th width="20%">分类</th>
                                                <th width="20%">控制器</th>
                                                <th>方法</th>
                                                <th></th>
                                            </tr>
                                        </thead>
                                        {volist name="data.ruleList" id="vo"}
                                        <tr>
                                            <td>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" <?php if(in_array($vo['id'], $data['access'])){echo 'checked';}?> name="rules[]" value="{$vo.id}">
                                                        {$vo.name}
                                                    </label>
                                                </div>
                                            </td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                            {notempty  name="vo.child"}
                                                {volist name="vo.child" id="son"}
                                                <tr>
                                                    <td></td>
                                                    <td>
                                                        <div class="checkbox">
                                                            <label>
                                                                <input type="checkbox" <?php if(in_array($son['id'], $data['access'])){echo 'checked';}?> name="rules[]" value="{$son.id}">
                                                                {$son.name}
                                                            </label>
                                                        </div>
                                                        <td>
                                                        {notempty  name="son.child"}
                                                            {volist name="son.child" id="grandSon"}
                                                                <div class="checkbox">
                                                                    <label>
                                                                        <input type="checkbox" <?php if(in_array($grandSon['id'], $data['access'])){echo 'checked';}?> name="rules[]" value="{$grandSon.id}">
                                                                        {$grandSon.name}
                                                                    </label>
                                                                </div>
                                                            {/volist}
                                                        {/notempty}
                                                        </td>
                                                    </td>
                                                    <td></td>
                                                </tr>
                                                {/volist}
                                            {/notempty}
                                        {/volist}
                                    </table>
                                </div>
                            </div>
                        </div>
                  </div>
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
                <div class="box-footer">
                    <div class="col-sm-offset-2 col-sm-10">
                        <div class="btn-group">
                            <input type="hidden" name="id" value="{$data.id}" >
                            <button class="btn btn-default btn-flat" type="reset">取消</button>
                            <button class="btn btn-primary btn-flat" id="submit" type="submit">保存</button>
                        </div>
                    </div>
                </div>
              </div>
              <!-- nav-tabs-custom -->
            </form>
    </div>

</section>
<!-- /.content -->
{/block}

{block name="js"}
<script>

    $(function(){

        $("#form").validate({
            rules: {
                name: {
                    required: true,
                    minlength: 1,
                    maxlength: 64
                }
            },
            submitHandler: function(form) {
                <!-- alert("submitted!"); -->
                $.ajax({
                    url:"{:Url('admin/group/update')}",
                    data:$(form).serialize(),
                    type:'post',
                    dataType:'json',
                    success:function(xhr){
                        if(xhr.code == 200){
                            swal({
                                title: xhr.msg,
                                text: "",
                                type: "success",
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                            });
                        } else{
                            swal({
                                title: xhr.msg,
                                text: "",
                                type: "error",
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                            });
                        }
                    }
                });

            }
        });

    });
</script>
{/block}